This document provides instructions for installing the following packages:
dataverse a package to download and read files from dataverses like Harvard’s Dataverse
DeclareDesign a set of packages useful for describing the properities of experimetnal and observational design
tidycensus set of functions of that allow us to download data from the US Census’ API
easystats a set of packages like the tidyverse but for statistics.
These are useful packages, but in the past, I’ve found they don’t play nicely with the simple the_packages ipak(the_packages) approach we take in class.
Additionally, for tidycensus, each of you will need to request an API key from the Census and install it locally to your computers.
In your console, please run each line of code separately
install.packages("dataverse")
install.packages("tidycensus")
install.packages("easystats", repos = "https://easystats.r-universe.dev")
install.packages("DeclareDesign")
R will typically install and or/update a package’s dependencies (other packages your package needs).R may tell you need to restart R Try saying yes. If it doesn’t start downloading, say no, see what happens. After the downloads are complete you may need to restart RR may then ask if you want to compile some packages from source. Type Y into your console. If this doesn’t work, try again, but this time type N when askedAgain, this is a pain and sort of cryptic, but you only have to do it once. Sometimes you’ll need to close and restart R for changes to take effect. Try working through these steps once or twice and if it still doesn’t work, shoot me an email.
If the installations went smoothly, you should see something like this when you run the following code:
require(dataverse)
## Loading required package: dataverse
require(tidycensus)
## Loading required package: tidycensus
require(DeclareDesign)
## Loading required package: DeclareDesign
## Loading required package: randomizr
## Loading required package: fabricatr
## Loading required package: estimatr
##
## Attaching package: 'DeclareDesign'
## The following object is masked from 'package:tidycensus':
##
## get_estimates
require(easystats)
## Loading required package: easystats
## # Attaching packages: easystats 0.4.3
## ✔ insight 0.16.0 ✔ datawizard 0.2.3
## ✔ bayestestR 0.11.5 ✔ performance 0.8.0.1
## ✔ parameters 0.16.0 ✔ effectsize 0.6.0.1
## ✔ modelbased 0.9.0 ✔ correlation 0.8.0
## ✔ see 0.6.9 ✔ report 0.5.1
If not, don’t worry. These packages aren’t strictly necessary for Thursday; You should be able to follow along with the slides, but just won’t be able to download the data and run the code on your machine.
We’ll go over this in class on Thursday, and I can troubleshoot installation problems after class.
tidycensus packageTo use the tidycensus package, you will need to do the following:
tidycensus packageSteps 1 and 2 should be done. So let’s walk through Steps 3-7:
Click on this link: https://api.census.gov/data/key_signup.html
And fill in the following information
firstname_lastname@brown.eduYou should receive an email like this:
Go back to the email from the census
census_api_key()census_api_key("YOUR API KEY GOES HERE")
census_api_key() should save your unique API to your .Renviron file which tidycensus will use whenever you make ask the Census to Download data.
If everything worked as planned, running Sys.getenv("CENSUS_API_KEY") should display your long API key
Sys.getenv("CENSUS_API_KEY")
And you should be able to use functions from tidycensus to download census data:
age10 <- tidycensus::get_decennial(geography = "state",
variables = "P013001",
year = 2010)
## Getting data from the 2010 decennial Census
## Using Census Summary File 1
head(age10)
## # A tibble: 6 × 4
## GEOID NAME variable value
## <chr> <chr> <chr> <dbl>
## 1 01 Alabama P013001 37.9
## 2 02 Alaska P013001 33.8
## 3 04 Arizona P013001 35.9
## 4 05 Arkansas P013001 37.4
## 5 06 California P013001 35.2
## 6 22 Louisiana P013001 35.8
You can read more about what tidycensus can do here